package Controllers;

import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import GUI.NXTTableModel;

/**
 * Class implementing the {@link ListSelectionListener} interface for
 * handling events from a {@link NXTTableModel}.
 * 
 * @author Danny Johansen, Didzis Petkus, Liviu Berheci.
 *
 */
public class TableSelectionController implements ListSelectionListener {

	private Controller parent;

	/**
	 * Constructor storing the passed <b>controller</b>. 
	 * 
	 * @param main - the passed {@link Controller} object.
	 */
	public TableSelectionController(Controller main) {
		this.parent = main;
	}

	@Override
	public void valueChanged(ListSelectionEvent event) {
		if (!event.getValueIsAdjusting()) {
			ListSelectionModel model = (ListSelectionModel) event.getSource();
			System.out.println("Selected index - "
					+ model.getMaxSelectionIndex());
			parent.toggleConnectBtn(!model.isSelectionEmpty());
		}
	}

}
